<template>
  <div class="container">
    <el-image :src="require('@/assets/img/lock.gif')" style="top:35%;left:25%;position: absolute;transform: translate(-50%, -50%);z-index: 13" fit="fill"></el-image>
    <div class="loginHuaconDownImage">
      <div class="imageGradient"></div>
    </div>
    <div class="loginForm loginHuaconForm">
      <div style="border-bottom: 1px solid #666;width:100%;height:110px;width:350px;display: inline-flex;align-items: center;justify-content: center;">
        <div style="width: 70px;">
          <el-image :src="require('@/assets/img/u33.png')" style="width: 70px;height:74px;" fit="fill"></el-image>
        </div>
        <div style="width: 250px;">
          <div class="menuLogoTitle">{{$t('力控华康工业防火墙')}}</div>
          <!-- <div class="menuLogoTitleEnglish">
            <div class="menuLogoWord">Huacon NISG</div>
            <div class="menuLogoLine"></div>
          </div> -->
        </div>
      </div>
      <el-form label-width="" :model="ruleForm" ref="ruleForm" :rules="loginRules" class="loginFormItem">
        <el-form-item label="" prop="username">
          <el-input v-emoji v-model="ruleForm.username" size="medium" class='inputClassUser' :placeholder="$t('用户名')"></el-input>
        </el-form-item>
        <el-form-item label="" prop="password">
          <el-input v-emoji type="password" size="medium" class='inputClassUser' :placeholder="$t('密码')" v-model="ruleForm.password" @keyup.enter.native="submitForm(ruleForm)"></el-input>
        </el-form-item>
        <el-button type="primary" class="loginButton loginHuaconButton" :loading="loading" size="small" @click.native.prevent="submitForm(ruleForm)">{{$t('登录')}}</el-button>
        <div class="authLoginModel">
          <el-link :underline="false" style="color: #fff;font-size: 12px;" @click="userAuthLoginClick">{{$t('用户认证')}}<i class="el-icon-arrow-right el-icon--right"></i> </el-link>
        </div>
      </el-form>
      <!-- <div style="border-top: 1px solid #666;color:#aaa;padding:5px;">
        Version: zoutestlog.113N.1
      </div> -->
    </div>
  </div>
</template>

<script>
import { setRoleList } from '@/utils/auth'
import { getMenu } from '@/api/menu'
export default {
  name: 'LoginHuacon',
  data () {
    const validateUsername = (rule, value, callback) => {
      if (!String(value).trim()) {
        callback(new Error(this.$t('请输入用户名')))
      } else {
        callback()
      }
    }
    const validatePassword = (rule, value, callback) => {
      if (!String(value).trim()) {
        callback(new Error(this.$t('请输入密码')))
      } else {
        callback()
      }
    }
    return {
      ruleForm: {
        username: '',
        password: ''
      },
      loading: false,
      loginRules: {
        username: [{ required: false, trigger: 'blur', validator: validateUsername }],
        password: [{ required: false, trigger: 'blur', validator: validatePassword }]
      }
    }
  },
  methods: {
    submitForm (ruleForm) {
      let _that = this
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          this.loading = true
          this.$store.dispatch('user/login', ruleForm).then(res => {
            // res.info[0].password_past = true;
            if (res.status === 0) {
              if (res.info[0].ukey !== 0) {
                this.OnLoadRead().then(r => {
                  setTimeout(function () {
                    _that.Arm_Enum_Read([res.info[0], _that.goMenu, _that.colseLoading])
                  }, 100)
                })
              } else {
                this.$store.dispatch('user/saveInfo', res.info[0]).then(() => {
                  getMenu({ roleID: res.info[0].roleID }).then((response) => {
                    if (response.status === 0) {
                      setRoleList(response.url_list)
                       this.$nextTick(() => {
                        this.loading = false
                        if (res.info[0].password_update_time === 0) {
                          this.$router.push('/changePassword')
                        } else {
                          this.$router.push('/')
                        }
                      })
                    }
                  }).catch(e => {
                    this.loading = false
                  })
                })
              }
              // this.$router.push('/network/physical/interface')
            } else {
              this.loading = false
            }
          }).catch(e => {
            this.loading = false
          })
        } else {
          console.log('error submit!!')
        }
      })
    },
    goMenu (info, status) {
      if (status !== 0) {
        this.loading = false
        this.$store.dispatch('user/logout')
        this.$messages.error(this.$t('UkeyAgain'))
      } else {
        this.$store.dispatch('user/saveInfo', info).then(() => {
          getMenu({ role: info.role }).then((response) => {
            if (response.status === 0) {
              setRoleList(response.url_list)
             this.$nextTick(() => {
                this.loading = false
                if (info.password_update_time === 0) {
                  this.$router.push('/changePassword')
                } else {
                  this.$router.push('/')
                }
              })
            }
          }).catch(e => {
            this.loading = false
          })
        })
      }
    },
    colseLoading () {
      this.loading = false
    },
    userAuthLoginClick () {
      const hrefUrl = window.location.href.match(/(http:\/\/|https:\/\/)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?/)
      const url = hrefUrl[0] + ':8183/#/authLogin'
      window.open(url)
    }
  }
}
</script>

<style scoped>
/* @import "D:\otherTry.css"; */
.container {
  /* width: 40%; */
  position: relative;
  width: 100%;
  height: 100vh;
  /* background: url("../../assets/img/keylogin.jpg") no-repeat center fixed; */
  background: #012138;
  background-size: cover;
  /* padding: 1px; */
  box-sizing: border-box;
  z-index: 1;
  /* overflow: hidden; */
  /* background-color: rgb(255, 255, 255, 0.5); */
}

.loginForm {
  position: absolute;
  left: 65%;
  top: 35%;
  transform: translate(-50%, -50%);
  text-align: center;
  /* border-radius: 10px; */
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3), 0 0 10px rgba(0, 0, 0, 0.1);
  z-index: 1001;
  background-color: #21252e;
  /* background-color: rgba(255, 255, 255, 0.6); */
  /* backdrop-filter: blur(5px); */
}
.loginTitle {
  margin: 0;
  /* height: 100px; */
  color: #fff;
  font-size: 24px;
  /* border-radius: 10px; */
  letter-spacing: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  /* background: url("../assets/img/snowMountain3.jpeg") no-repeat;
  background-size: cover;
  background-position: 0% 50%; */
}
.loginFormItem {
  margin-top: 20px;
  margin: 40px 40px 30px;
  width: 270px;
}
.loginButton {
  width: 100%;
  margin-top: 28px;
  border: none;
  /* background-image: linear-gradient(to right, #336699, #009999),
    linear-gradient(to right, #336699, #009999); */
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
  z-index: 10;
}
.authLoginModel {
  text-align: right;
  margin-top: 5px;
}
.menuLogoTitle {
  font-size: 24px;
  color: #fff;
  /* letter-spacing: 3px; */
}
.menuLogoTitleEnglish {
  position: relative;
  font-size: 12px;
  color: #fff;
  width: 216px;
  height: 12px;
  line-height: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.menuLogoWord {
  position: absolute;
  line-height: 12px;
  height: 12px;
  z-index: 1001;
  width: 100px;
  background-color: #21252e;
  margin: 0 auto;
}
.menuLogoLine {
  position: absolute;
  width: 216px;
  border-bottom: 1px solid #cccccc;
  top: 6px;
}
</style>
<style lang='scss'>
.loginHuaconForm {
  .el-input__inner {
    color: #fff;
    border: 2px solid #555 !important;
    background-color: #14191d !important;
  }
  .is-error .el-input__inner {
    border: 2px solid #ff4949 !important;
  }
  .el-input__inner::placeholder {
    color: #555;
  }
  .el-button--small {
    border-radius: 0px;
  }
  input:-internal-autofill-previewed,
  input:-internal-autofill-selected {
    -webkit-text-fill-color: #fff;
    transition: background-color 1000s ease-out 0.5s;
  }
}
.loginHuaconDownImage {
  top: 60%;
  height: 40%;
  width: 100%;
  position: absolute;
  z-index: 3;
  background: url("../../assets/img/particle.gif") no-repeat;
  background-size: cover;
  background-position: center 50px;
}
</style>
<style>
.loginHuaconButton::before {
  width: 270px !important;
  height: 30.5px;
  margin-left: 1px;
  margin-top: 1px;
}
.imageGradient {
  width: 100%;
  height: 100%;
  background: linear-gradient(#012138 30%, rgba(255, 255, 255, 0));
}
</style>
